/*AyflEomXWyqCHfdTxzWda+ZiNDhxOZJeZF/oshAh0uo=*/
/*
 * @Author: xiahui 
 * @PageInfo: 采购合同付款计划
 * @Date: 2019-02-28 20:10:51 
 * @Last Modified by: zhr
 * @Last Modified time: 2021-11-03 14:49:29
 */
import React, { Component } from 'react';
import { createPage, createPageIcon, high, base } from 'nc-lightapp-front';
import initTemplate from './init/initTemplate';
const { NCAffix, NCDiv } = base;
import { AREA, PAGECODE, UISTATUS, FIELDS } from '../constance';
import { buttonClick, searchBtnClick } from './btnClicks';
import { buttonControl } from './viewControl/buttonControl';
import { bodyBeforeEvent } from './beforeEvents';
import { bodyAfterEvent, searchAfterEvent } from './afterEvents';
import { initLang, getLangByResId } from '../../../../scmpub/scmpub/pub/tool/multiLangUtil';
import { createListTitle } from '../../../../scmpub/scmpub/pub/tool/titleUtil';

const { BillTrack } = high;

class PayplanList extends Component {
	constructor(props) {
		super(props);

		props.use.search(AREA.searchId);
		props.use.editTable(AREA.listTableId);

		this.state = {
			pk: '',
			showTrack: false,
			status: UISTATUS.browse // 页面当前状态
		};
		this.queryInfo = null; // 查询条件
		initLang(this, [ '4004payplan' ], 'ct', initTemplate.bind(this, this.props));
	}

	componentWillMount() {
		// 关闭浏览器
		window.onbeforeunload = () => {
			let status = this.props.editTable.getStatus(AREA.listTableId);
			if (status == UISTATUS.edit) {
				return getLangByResId(this, '4004PAYPLAN-000006'); /* 国际化处理： 当前单据未保存，您确认离开此页面*/
			}
		};
	}

	querySchemeAfterEvent = () => {
		searchAfterEvent.call(this, FIELDS.pk_org);
	};

	render() {
		const { button, search, editTable } = this.props;
		const { createButtonApp } = button;
		const { NCCreateSearch } = search;
		const { createEditTable } = editTable;

		return (
			<div className="nc-bill-list">
				<NCAffix>
					<NCDiv areaCode={NCDiv.config.HEADER} className="nc-bill-header-area">
						<div className="header-title-search-area">
							{createListTitle(this)}
							{/* 国际化处理： 采购合同付款计划*/}
						</div>
						<div className="header-button-area">
							{createButtonApp({
								area: AREA.list_head,
								onButtonClick: buttonClick.bind(this)
							})}
						</div>
					</NCDiv>
				</NCAffix>
				{this.state.status == UISTATUS.browse ? (
					<div className="nc-bill-search-area">
						{NCCreateSearch(AREA.searchId, {
							clickSearchBtn: searchBtnClick.bind(this),
							onAfterEvent: searchAfterEvent.bind(this),
							// 平台提供的两个回调
							renderCompleteEvent: this.querySchemeAfterEvent,
							statusChangeEvent: this.querySchemeAfterEvent
						})}
					</div>
				) : (
					''
				)}
				<div className="nc-bill-table-area">
					{createEditTable(AREA.listTableId, {
						showIndex: true,
						showCheck: true,
						adaptionHeight: true,
						onAfterEvent: bodyAfterEvent.bind(this),
						onBeforeEvent: bodyBeforeEvent.bind(this),
						onSelected: onSelect.bind(this),
						onSelectedAll: onSelect.bind(this)
					})}
				</div>
				<BillTrack
					show={this.state.showTrack}
					close={() => {
						this.setState({ showTrack: false });
					}}
					pk={this.state.pk}
					type="Z2"
				/>
			</div>
		);
	}
}

function onSelect() {
	let checkArr = this.props.editTable.getCheckedRows(AREA.listTableId);
	buttonControl.call(this, this.props, this.state.status, checkArr);
}

PayplanList = createPage({
	billinfo: {
		billtype: 'grid',
		pagecode: PAGECODE.listPagecode,
		bodycode: {
			[AREA.listTableId]: 'table'
		}
	}
})(PayplanList);

export default PayplanList;

/*AyflEomXWyqCHfdTxzWda+ZiNDhxOZJeZF/oshAh0uo=*/